package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tiantianyuegou.R;
import com.tiantianyuegou.model.SpecModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huyang on 2016/1/21 0021.
 */
public class GoodsDetailAdapter extends BaseAdapter {

    private Context context;
    private List<SpecModel> data;

    public GoodsDetailAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    public GoodsDetailAdapter(List<SpecModel> data, Context context) {
        this.data = data;
        this.context = context;
    }

    public void setData(List<SpecModel> data) {
        this.data.clear();
        this.data.addAll(data);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent) {
        SpecModel model = data.get(position);
        final ViewHolder holder;
        if (converView==null){
            holder=new ViewHolder();
            converView=LayoutInflater.from(context).inflate(R.layout.activtiy_goodsdetail,null);
            holder.tpName= (TextView) converView.findViewById(R.id.tv_goodsname);
            holder.tpPrice= (TextView) converView.findViewById(R.id.tv_price);
            holder.tpSalePrice= (TextView) converView.findViewById(R.id.tv_saleprice);
            holder.tpStore= (TextView) converView.findViewById(R.id.tv_store);
            holder.tpSaleCount= (TextView) converView.findViewById(R.id.tv_salecount);
            converView.setTag(holder);
        }else{
            holder= (ViewHolder) converView.getTag();
        }
//        holder.tpName.setText(model.getTpName());
//        holder.tpPrice.setText("¥"+model.getTpPrice());
//        holder.tpSalePrice.setText("¥"+model.getTpSalePrice());
//        holder.tpSaleCount.setText(model.getTpSalesCount());
//        holder.tpStore.setText(model.getTpStroe());

        return converView;
    }

    class ViewHolder {
        TextView tpName;
        TextView tpPrice;
        TextView tpSalePrice;
        TextView tpDiscountPrice;
        TextView tpStore;
        TextView tpSaleCount;

    }
}
